package com.example.demo.controller;

import com.example.demo.controller.vo.CourseDetailVO;
import com.example.demo.entity.CourseInfo;
import com.example.demo.entity.CoursePO;
import com.example.demo.service.CourseService;
import com.example.demo.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date:
 * @ClassName:CourseController
 * @Description: TODO
 */
@Controller
@RequestMapping("/course")
@CrossOrigin
@ResponseBody
@Api("课程相关接口")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @ApiOperation("获取课程详情")
    @GetMapping("/getCourseDetail")
    public AjaxResult getCourseDetail(@RequestParam("id")@ApiParam("课程id") long id){

        CoursePO courseDetailVO = courseService.getCourseDetail(id);

        return new AjaxResult().ok(courseDetailVO);
    }




//    @ApiOperation("获取个人已购课程列表")
//    @GetMapping("/getCourseList")
//    public AjaxResult getCourseListByUserId(@RequestParam("userId")@ApiParam("用户id") String userId,
//                                            @RequestParam("type")@ApiParam("排序key，1：无排序，2：销量，3：价格") int type){
//        List<CoursePO> courseDetailVOs = courseService.getCourseListByUserId(userId,type);
//        return new AjaxResult().ok(courseDetailVOs);
//    }

    @ApiOperation("获取个人已购课程列表")
    @GetMapping("/getCourseList")
    public AjaxResult getCourseListByUserId(@RequestParam("userId")@ApiParam("用户id") String userId,
                                            @RequestParam("type")@ApiParam("排序key，1：无排序，2：销量，3：价格") int type){
        List<CoursePO> courseDetailVOs = courseService.getCourseList(userId);
        return new AjaxResult().ok(courseDetailVOs);
    }



    @ApiOperation("获取推荐课程列表")
    @GetMapping("/getCourse")
    public AjaxResult getMarkCourseList(@RequestParam("type")@ApiParam("排序key，1：无排序，2：销量，3：价格") int type){
        List<CoursePO> courseDetailVOs = courseService.getCourseListByTuijian(type);
        return new AjaxResult().ok(courseDetailVOs);
    }



    @ApiOperation("根据课程标题模糊搜索课程信息")
    @GetMapping("/getMarkCourseListByTitle")
    public AjaxResult getMarkCourseListByTitle(
                                               @RequestParam("title")@ApiParam("标题") String title){
        List<CoursePO> courseDetailVOs = courseService.getMarkCourseListByTitle(title);
        return new AjaxResult().ok(courseDetailVOs);
    }

//    @ApiOperation("根据课程标题模糊搜索课程信息")
//    @GetMapping("/getMarkCourseListByTitle")
//    public AjaxResult getMarkCourseListByTitle(@RequestParam("type")@ApiParam("排序key，1：无排序，2：销量，3：价格") int type,
//                                               @RequestParam("title")@ApiParam("标题") String title){
//        List<CoursePO> courseDetailVOs = courseService.getMarkCourseListByTitle(type,title);
//        return new AjaxResult().ok(courseDetailVOs);
//    }


//    @ApiOperation("获取订单列表")
//    @GetMapping("/getOrderList")
//    public AjaxResult getMarkCourseListByTitle(@RequestParam("title")@ApiParam("标题") String title){
//        List<long> courseDetailVOs = courseService.getMarkCourseListByTitle(title);
//        return new AjaxResult().ok(courseDetailVOs);
//    }
}
